Passed
Push — master ( fe7b3f...22651e )
by Andrey
08:30
created

PBSyntaxHighlighter.constructor   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 75
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 34
nc 1
nop 0
dl 0
loc 75
c 0
b 0
f 0
cc 1
rs 9.064

1 Function

Rating   Name   Duplication   Size   Complexity  
A PBSyntaxHighlighter.js ➔ PBSyntaxHighlighter 0 23 3

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
var PBSyntaxHighlighter = (function() {
2
  "use strict";
3
4
  var sh;
5
6
  /**
7
   * Constructor
8
   * @param {String} sh The SyntaxHighlighter
9
   */
10
  function PBSyntaxHighlighter(sh) {
11
    switch (sh) {
12
      case "HIGHLIGHT" :
13
        this.sh = HIGHLIGHT;
14
        break;
15
      case "PRETTIFY" :
16
        this.sh = PRETTIFY;
17
        break;
18
      case "PRISM" :
19
        this.sh = PRISM;
20
        break;
21
      case "SYNTAX_HIGHLIGHTER" :
22
        this.sh = SYNTAX_HIGHLIGHTER;
23
        break;
24
      default :
25
        this.sh = {
26
          _type: "DEFAULT",
27
          _cls: "",
28
          _tag: 'pre'
29
        };
30
        break;
31
    }
32
  }
33
34
  /**
35
   * Sets the SyntaxHighlighter type
36
   * @param {String} type The name of the SyntaxHighlighter
37
   */
38
  PBSyntaxHighlighter.prototype.setType = function(type) {
39
    this.sh._type = type;
40
  };
41
42
  /**
43
   * Gets the SyntaxHighlighter type
44
   * @return {String} The type of the SyntaxHighlighter
45
   */
46
  PBSyntaxHighlighter.prototype.getType = function() {
47
    return this.sh._type;
48
  };
49
50
  /**
51
   * Sets the full class of the SH object
52
   * @param {String} cls the class to add to the Object
53
   */
54
  PBSyntaxHighlighter.prototype.setCls = function(cls) {
55
    this.sh.cls = this.sh._cls + cls;
56
  };
57
58
  /**
59
   * Gets the full class of the SH Object
60
   * @return {String} the full class of the SH Object
61
   */
62
  PBSyntaxHighlighter.prototype.getCls = function() {
63
    return this.sh.cls;
64
  };
65
66
  /**
67
   * Get the tag to insert into the pre tag
68
   * @return {String} the tag to insert, pre otherwise
69
   */
70
  PBSyntaxHighlighter.prototype.getTag = function() {
71
    return this.sh._tag;
72
  };
73
74
  return PBSyntaxHighlighter;
75
})();
76
77
/**********************************/
78
/* SYNTAX HIGHLIGHTERS DEFINITION */
79
/**********************************/
80
var HIGHLIGHT = {
81
  _type: "HIGHLIGHT",
82
  _cls: "", // only show language (done in pbckcode.js)
83
  _tag: 'code'
84
};
85
86
var PRETTIFY = {
87
  _type: "PRETTIFY",
88
  _cls: "prettyprint linenums lang-",
89
  _tag: 'pre'
90
};
91
92
var PRISM = {
93
  _type: "PRISM",
94
  _cls: "language-",
95
  _tag: 'code'
96
};
97
98
var SYNTAX_HIGHLIGHTER = {
99
  _type: "SYNTAX_HIGHLIGHTER",
100
  _cls: "brush: ",
101
  _tag: 'pre'
102
};
103